package com.zshan.clinic.web.controller.stock;


import com.zshan.clinic.admin.entity.vo.*;
import com.zshan.clinic.admin.service.stock.StockSupplyService;
import com.zshan.clinic.common.response.RestResp;
import com.zshan.clinic.common.util.page.PageInfo;
import com.zshan.clinic.database.model.StockMfr;
import com.zshan.clinic.database.model.StockStorage;
import com.zshan.clinic.database.model.StockSupply;
import com.zshan.clinic.web.controller.AbstractController;
import com.zshan.clinic.web.entity.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 库房支持
 */
@RestController
@RequestMapping("/stock/supply")
public class StockSupplyController extends AbstractController {


    @Autowired
    private StockSupplyService stockSupplyService;

    /**
     * 门诊：查询药库列表
     * @param
     * @return
     */
    @GetMapping("/getStorageSelectList")
    public RestResp<List<StockStorageSelectVo>> getStorageSelectList() {
        UserInfo userInfo = getUserInfo();
        List<StockStorageSelectVo> selectList = stockSupplyService.getStorageSelectList(userInfo.getClinicId());
        return RestResp.SUCCESS(selectList);
    }

    /**
     * 查询药库列表
     * @param
     * @return
     */
    @GetMapping("/getStorageList")
    public RestResp<PageInfo<StockStorageVo>> getStorageList(@RequestParam(name = "storageName", required = false) String storageName,
                                                             @RequestParam(name = "pageNo", defaultValue = "1", required = false) Integer pageNo,
                                                             @RequestParam(name = "pageSize", defaultValue = "10", required = false) Integer pageSize) {
        UserInfo userInfo = getUserInfo();
        PageInfo<StockStorageVo> storageList = stockSupplyService.getStorageList(userInfo.getClinicId(), storageName, pageNo, pageSize);
        return RestResp.SUCCESS(storageList);
    }

    /**
     * 添加药库
     * @return
     */
    @PostMapping("/addStorage")
    public RestResp<Void> addStorage(@RequestBody StockStorage stockStorage) {
        UserInfo userInfo = getUserInfo();
        stockStorage.setCreateUserId(userInfo.getEmpId());
        stockStorage.setCreateBy(userInfo.getEmpName());
        stockStorage.setClinicId(userInfo.getClinicId());
        stockSupplyService.addStorage(stockStorage);
        return RestResp.SUCCESS();
    }

    /**
     * 设置默认药库
     * @return
     */
    @PostMapping("/setDefault")
    public RestResp<Void> setDefault(@RequestBody StockStorage stockStorage) {
        UserInfo userInfo = getUserInfo();
        stockStorage.setUpdateUserId(userInfo.getEmpId());
        stockStorage.setUpdateBy(userInfo.getEmpName());
        stockStorage.setClinicId(userInfo.getClinicId());
        stockSupplyService.setDefault(stockStorage);
        return RestResp.SUCCESS();
    }

    /**
     * 编辑药库
     * @return
     */
    @PostMapping("/updateStorage")
    public RestResp<Void> updateStorage(@RequestBody StockStorage stockStorage) {
        UserInfo userInfo = getUserInfo();
        stockStorage.setUpdateUserId(userInfo.getEmpId());
        stockStorage.setUpdateBy(userInfo.getEmpName());
        stockStorage.setClinicId(userInfo.getClinicId());
        stockSupplyService.updateStorage(stockStorage);
        return RestResp.SUCCESS();
    }

    /**
     * 删除药库
     * @return
     */
    @PostMapping("/deleteStorage")
    public RestResp<Void> deleteStorage(@RequestBody StockStorage stockStorage) {
        UserInfo userInfo = getUserInfo();
        stockStorage.setUpdateUserId(userInfo.getEmpId());
        stockStorage.setUpdateBy(userInfo.getEmpName());
        stockStorage.setClinicId(userInfo.getClinicId());
        stockSupplyService.deleteStorage(stockStorage);
        return RestResp.SUCCESS();
    }

    /**
     * 启用药库
     * @return
     */
    @PostMapping("/enableStorage")
    public RestResp<Void> enableStorage(@RequestBody StockStorage stockStorage) {
        UserInfo userInfo = getUserInfo();
        stockStorage.setUpdateUserId(userInfo.getEmpId());
        stockStorage.setUpdateBy(userInfo.getEmpName());
        stockStorage.setClinicId(userInfo.getClinicId());
        stockSupplyService.enableStorage(stockStorage);
        return RestResp.SUCCESS();
    }

    /**
     * 停用药库
     * @return
     */
    @PostMapping("/disableStorage")
    public RestResp<Void> disableStorage(@RequestBody StockStorage stockStorage) {
        UserInfo userInfo = getUserInfo();
        stockStorage.setUpdateUserId(userInfo.getEmpId());
        stockStorage.setUpdateBy(userInfo.getEmpName());
        stockStorage.setClinicId(userInfo.getClinicId());
        stockSupplyService.disableStorage(stockStorage);
        return RestResp.SUCCESS();
    }

    /**
     * 查询厂家下拉框
     * @param
     * @return
     */
    @GetMapping("/getMfrSelectList")
    public RestResp<List<StockMfrSelectVo>> getMfrSelectList() {
        UserInfo userInfo = getUserInfo();
        List<StockMfrSelectVo> selectList = stockSupplyService.getMfrSelectList(userInfo.getClinicId());
        return RestResp.SUCCESS(selectList);
    }

    /**
     * 查询厂家列表
     * @param
     * @return
     */
    @GetMapping("/getMfrList")
    public RestResp<PageInfo<StockMfrVo>> getMfrList(@RequestParam(name = "mfrName", required = false) String mfrName,
                                                     @RequestParam(name = "pageNo", defaultValue = "1", required = false) Integer pageNo,
                                                     @RequestParam(name = "pageSize", defaultValue = "10", required = false) Integer pageSize) {
        UserInfo userInfo = getUserInfo();
        PageInfo<StockMfrVo> mfrList = stockSupplyService.getMfrList(userInfo.getClinicId(), mfrName, pageNo, pageSize);
        return RestResp.SUCCESS(mfrList);
    }

    /**
     * 添加厂家
     * @return
     */
    @PostMapping("/addMfr")
    public RestResp<Void> addMfr(@RequestBody StockMfr stockMfr) {
        UserInfo userInfo = getUserInfo();
        stockMfr.setCreateUserId(userInfo.getEmpId());
        stockMfr.setCreateBy(userInfo.getEmpName());
        stockMfr.setClinicId(userInfo.getClinicId());
        stockSupplyService.addMfr(stockMfr);
        return RestResp.SUCCESS();
    }

    /**
     * 编辑厂家
     * @return
     */
    @PostMapping("/updateMfr")
    public RestResp<Void> updateMfr(@RequestBody StockMfr stockMfr) {
        UserInfo userInfo = getUserInfo();
        stockMfr.setUpdateUserId(userInfo.getEmpId());
        stockMfr.setUpdateBy(userInfo.getEmpName());
        stockMfr.setClinicId(userInfo.getClinicId());
        stockSupplyService.updateMfr(stockMfr);
        return RestResp.SUCCESS();
    }

    /**
     * 删除厂家
     * @return
     */
    @PostMapping("/deleteMfr")
    public RestResp<Void> deleteMfr(@RequestBody StockMfr stockMfr) {
        UserInfo userInfo = getUserInfo();
        stockMfr.setUpdateUserId(userInfo.getEmpId());
        stockMfr.setUpdateBy(userInfo.getEmpName());
        stockMfr.setClinicId(userInfo.getClinicId());
        stockSupplyService.deleteMfr(stockMfr);
        return RestResp.SUCCESS();
    }

    /**
     * 启用厂家
     * @return
     */
    @PostMapping("/enableMfr")
    public RestResp<Void> enableMfr(@RequestBody StockMfr stockMfr) {
        UserInfo userInfo = getUserInfo();
        stockMfr.setUpdateUserId(userInfo.getEmpId());
        stockMfr.setUpdateBy(userInfo.getEmpName());
        stockMfr.setClinicId(userInfo.getClinicId());
        stockSupplyService.enableMfr(stockMfr);
        return RestResp.SUCCESS();
    }

    /**
     * 停用厂家
     * @return
     */
    @PostMapping("/disableMfr")
    public RestResp<Void> disableMfr(@RequestBody StockMfr stockMfr) {
        UserInfo userInfo = getUserInfo();
        stockMfr.setUpdateUserId(userInfo.getEmpId());
        stockMfr.setUpdateBy(userInfo.getEmpName());
        stockMfr.setClinicId(userInfo.getClinicId());
        stockSupplyService.disableMfr(stockMfr);
        return RestResp.SUCCESS();
    }


    /**
     * 查询供应商下拉框
     * @param
     * @return
     */
    @GetMapping("/getSupplySelectList")
    public RestResp<List<StockSupplySelectVo>> getSupplySelectList() {
        UserInfo userInfo = getUserInfo();
        List<StockSupplySelectVo> selectList = stockSupplyService.getSupplySelectList(userInfo.getClinicId());
        return RestResp.SUCCESS(selectList);
    }


    /**
     * 查询供应商列表
     * @param
     * @return
     */
    @GetMapping("/getSupplyList")
    public RestResp<PageInfo<StockSupplyVo>> getSupplyList(@RequestParam(name = "supplyName", required = false) String supplyName,
                                                           @RequestParam(name = "pageNo", defaultValue = "1", required = false) Integer pageNo,
                                                           @RequestParam(name = "pageSize", defaultValue = "10", required = false) Integer pageSize) {
        UserInfo userInfo = getUserInfo();
        PageInfo<StockSupplyVo> supplyList = stockSupplyService.getSupplyList(userInfo.getClinicId(), supplyName, pageNo, pageSize);
        return RestResp.SUCCESS(supplyList);
    }

    /**
     * 添加供应商
     * @return
     */
    @PostMapping("/addSupply")
    public RestResp<Void> addSupply(@RequestBody StockSupply supply) {
        UserInfo userInfo = getUserInfo();
        supply.setCreateUserId(userInfo.getEmpId());
        supply.setCreateBy(userInfo.getEmpName());
        supply.setClinicId(userInfo.getClinicId());
        stockSupplyService.addSupply(supply);
        return RestResp.SUCCESS();
    }

    /**
     * 编辑供应商
     * @return
     */
    @PostMapping("/updateSupply")
    public RestResp<Void> updateSupply(@RequestBody StockSupply supply) {
        UserInfo userInfo = getUserInfo();
        supply.setUpdateUserId(userInfo.getEmpId());
        supply.setUpdateBy(userInfo.getEmpName());
        supply.setClinicId(userInfo.getClinicId());
        stockSupplyService.updateSupply(supply);
        return RestResp.SUCCESS();
    }

    /**
     * 删除供应商
     * @return
     */
    @PostMapping("/deleteSupply")
    public RestResp<Void> deleteSupply(@RequestBody StockSupply supply) {
        UserInfo userInfo = getUserInfo();
        supply.setUpdateUserId(userInfo.getEmpId());
        supply.setUpdateBy(userInfo.getEmpName());
        supply.setClinicId(userInfo.getClinicId());
        stockSupplyService.deleteSupply(supply);
        return RestResp.SUCCESS();
    }

    /**
     * 启用供应商
     * @return
     */
    @PostMapping("/enableSupply")
    public RestResp<Void> enableSupply(@RequestBody StockSupply supply) {
        UserInfo userInfo = getUserInfo();
        supply.setUpdateUserId(userInfo.getEmpId());
        supply.setUpdateBy(userInfo.getEmpName());
        supply.setClinicId(userInfo.getClinicId());
        stockSupplyService.enableSupply(supply);
        return RestResp.SUCCESS();
    }

    /**
     * 停用供应商
     * @return
     */
    @PostMapping("/disableSupply")
    public RestResp<Void> disableSupply(@RequestBody StockSupply supply) {
        UserInfo userInfo = getUserInfo();
        supply.setUpdateUserId(userInfo.getEmpId());
        supply.setUpdateBy(userInfo.getEmpName());
        supply.setClinicId(userInfo.getClinicId());
        stockSupplyService.disableSupply(supply);
        return RestResp.SUCCESS();
    }


}
